package com.ybkj.o2o.zhuanche.thrift;

import org.apache.thrift.EncodingUtils;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;
import org.apache.thrift.scheme.TupleScheme;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Generated;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-12-05")
public class IdsResult implements org.apache.thrift.TBase<IdsResult, IdsResult.Fields>,
    java.io.Serializable, Cloneable, Comparable<IdsResult> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC =
      new org.apache.thrift.protocol.TStruct("IdsResult");

  private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC =
      new org.apache.thrift.protocol.TField(
          "code", org.apache.thrift.protocol.TType.I32, (short) 1);
  private static final org.apache.thrift.protocol.TField IDS_FIELD_DESC =
      new org.apache.thrift.protocol.TField(
          "ids", org.apache.thrift.protocol.TType.LIST, (short) 2);
  private static final org.apache.thrift.protocol.TField MSG_FIELD_DESC =
      new org.apache.thrift.protocol.TField("msg", org.apache.thrift.protocol.TType.STRING,
          (short) 3);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes =
      new HashMap<Class<? extends IScheme>, SchemeFactory>();
  
  static {
    schemes.put(StandardScheme.class, new IdsResultStandardSchemeFactory());
    schemes.put(TupleScheme.class, new IdsResultTupleSchemeFactory());
  }

  public int code; // required
  public List<Long> ids; // required
  public String msg; // optional

  /**
   * The set of fields this struct contains, along with convenience methods for finding and
   * manipulating them.
   */
  public enum Fields implements org.apache.thrift.TFieldIdEnum {
    CODE((short) 1, "code"), IDS((short) 2, "ids"), MSG((short) 3, "msg");

    private static final Map<String, Fields> byName = new HashMap<String, Fields>();

    static {
      for (Fields field : EnumSet.allOf(Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the Fields constant that matches fieldId, or null if its not found.
     */
    public static Fields findByThriftId(int fieldId) {
      switch (fieldId) {
        case 1: // CODE
          return CODE;
        case 2: // IDS
          return IDS;
        case 3: // MSG
          return MSG;
        default:
          return null;
      }
    }

    /**
     * Find the Fields constant that matches fieldId, throwing an exception if it is not found.
     */
    public static Fields findByThriftIdOrThrow(int fieldId) {
      Fields fields = findByThriftId(fieldId);
      if (fields == null) {
        throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      }
      return fields;
    }

    /**
     * Find the Fields constant that matches name, or null if its not found.
     */
    public static Fields findByName(String name) {
      return byName.get(name);
    }

    private final short thriftId;
    private final String fieldName;

    Fields(short id, String name) {
      thriftId = id;
      fieldName = name;
    }

    public short getThriftFieldId() {
      return thriftId;
    }

    public String getFieldName() {
      return fieldName;
    }
  }

  // isset id assignments
  private static final int __CODE_ISSET_ID = 0;
  private byte issetBitfield = 0;
  public static final Map<Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  
  static {
    Map<Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap =
        new EnumMap<Fields, org.apache.thrift.meta_data.FieldMetaData>(Fields.class);
    tmpMap.put(Fields.CODE, new org.apache.thrift.meta_data.FieldMetaData("code",
        org.apache.thrift.TFieldRequirementType.DEFAULT,
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
    tmpMap.put(Fields.IDS,
        new org.apache.thrift.meta_data.FieldMetaData("ids",
            org.apache.thrift.TFieldRequirementType.DEFAULT,
            new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
                new org.apache.thrift.meta_data.FieldValueMetaData(
                    org.apache.thrift.protocol.TType.I64))));
    tmpMap.put(Fields.MSG,
        new org.apache.thrift.meta_data.FieldMetaData("msg",
            org.apache.thrift.TFieldRequirementType.OPTIONAL,
            new org.apache.thrift.meta_data.FieldValueMetaData(
                org.apache.thrift.protocol.TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(IdsResult.class, metaDataMap);
  }

  public IdsResult() {
    this.code = 0;

  }

  /**
   * id集合.
   */
  public IdsResult(int code, List<Long> ids) {
    this();
    this.code = code;
    setCodeIsSet(true);
    this.ids = ids;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public IdsResult(IdsResult other) {
    issetBitfield = other.issetBitfield;
    this.code = other.code;
    if (other.isSetIds()) {
      List<Long> thisIds = new ArrayList<Long>(other.ids);
      this.ids = thisIds;
    }
    if (other.isSetMsg()) {
      this.msg = other.msg;
    }
  }

  public IdsResult deepCopy() {
    return new IdsResult(this);
  }

  @Override
  public void clear() {
    this.code = 0;

    this.ids = null;
    this.msg = null;
  }

  public int getCode() {
    return this.code;
  }

  /**
   * 设置值.
   */
  public IdsResult setCode(int code) {
    this.code = code;
    setCodeIsSet(true);
    return this;
  }

  public void unsetCode() {
    issetBitfield = EncodingUtils.clearBit(issetBitfield, __CODE_ISSET_ID);
  }

  /** Returns true if field code is set (has been assigned a value) and false otherwise. */
  public boolean isSetCode() {
    return EncodingUtils.testBit(issetBitfield, __CODE_ISSET_ID);
  }

  public void setCodeIsSet(boolean value) {
    issetBitfield = EncodingUtils.setBit(issetBitfield, __CODE_ISSET_ID, value);
  }

  public int getIdsSize() {
    return (this.ids == null) ? 0 : this.ids.size();
  }

  public java.util.Iterator<Long> getIdsIterator() {
    return (this.ids == null) ? null : this.ids.iterator();
  }

  /**
   * 为空则新建空集合.
   */
  public void addToIds(long elem) {
    if (this.ids == null) {
      this.ids = new ArrayList<Long>();
    }
    this.ids.add(elem);
  }

  public List<Long> getIds() {
    return this.ids;
  }

  public IdsResult setIds(List<Long> ids) {
    this.ids = ids;
    return this;
  }

  public void unsetIds() {
    this.ids = null;
  }

  /** Returns true if field ids is set (has been assigned a value) and false otherwise. */
  public boolean isSetIds() {
    return this.ids != null;
  }

  /**
   * false设置为空.
   */
  public void setIdsIsSet(boolean value) {
    if (!value) {
      this.ids = null;
    }
  }

  public String getMsg() {
    return this.msg;
  }

  public IdsResult setMsg(String msg) {
    this.msg = msg;
    return this;
  }

  public void unsetMsg() {
    this.msg = null;
  }

  /** Returns true if field msg is set (has been assigned a value) and false otherwise. */
  public boolean isSetMsg() {
    return this.msg != null;
  }

  /**
   * false设置为空.
   */
  public void setMsgIsSet(boolean value) {
    if (!value) {
      this.msg = null;
    }
  }

  /**
   * 设置字段值.
   */
  public void setFieldValue(Fields field, Object value) {
    switch (field) {
      case CODE:
        if (value == null) {
          unsetCode();
        } else {
          setCode((Integer) value);
        }
        break;

      case IDS:
        if (value == null) {
          unsetIds();
        } else {
          setIds((List<Long>) value);
        }
        break;

      case MSG:
        if (value == null) {
          unsetMsg();
        } else {
          setMsg((String) value);
        }
        break;

      default:

    }
  }

  /**
   * 获取字段值.
   */
  public Object getFieldValue(Fields field) {
    switch (field) {
      case CODE:
        return getCode();

      case IDS:
        return getIds();

      case MSG:
        return getMsg();
        
      default:

    }
    throw new IllegalStateException();
  }

  /**
   * Returns true if field corresponding to fieldID is set (has been assigned a value) and false.
   */
  public boolean isSet(Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
      case CODE:
        return isSetCode();
      case IDS:
        return isSetIds();
      case MSG:
        return isSetMsg();
      default:
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null) {
      return false;
    }
    if (that instanceof IdsResult) {
      return this.equals((IdsResult) that);
    }
    return false;
  }

  /**
   * 比较值.
   */
  public boolean equals(IdsResult that) {
    if (that == null) {
      return false;
    }
    boolean thisPresentCode = true;
    boolean thatPresentCode = true;
    if (thisPresentCode || thatPresentCode) {
      if (!(thisPresentCode && thatPresentCode)) {
        return false;
      }
      if (this.code != that.code) {
        return false;
      }
    }

    boolean thisPresentIds = true && this.isSetIds();
    boolean thatPresentIds = true && that.isSetIds();
    if (thisPresentIds || thatPresentIds) {
      if (!(thisPresentIds && thatPresentIds)) {
        return false;
      }
      if (!this.ids.equals(that.ids)) {
        return false;
      }
    }

    boolean thisPresentMsg = true && this.isSetMsg();
    boolean thatPresentMsg = true && that.isSetMsg();
    if (thisPresentMsg || thatPresentMsg) {
      if (!(thisPresentMsg && thatPresentMsg)) {
        return false;
      }
      if (!this.msg.equals(that.msg)) {
        return false;
      }
    }

    return true;
  }

  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean presentCode = true;
    list.add(presentCode);
    if (presentCode) {
      list.add(code);
    }
      
    boolean presentIds = true && (isSetIds());
    list.add(presentIds);
    if (presentIds) {
      list.add(ids);
    }
    boolean presentMsg = true && (isSetMsg());
    list.add(presentMsg);
    if (presentMsg) {
      list.add(msg);
    }

    return list.hashCode();
  }

  @Override
  public int compareTo(IdsResult other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetCode()).compareTo(other.isSetCode());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetCode()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetIds()).compareTo(other.isSetIds());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetIds()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.ids, other.ids);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetMsg()).compareTo(other.isSetMsg());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetMsg()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.msg, other.msg);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public Fields fieldForId(int fieldId) {
    return Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) 
      throws org.apache.thrift.TException {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) 
      throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("IdsResult(");
    boolean first = true;

    sb.append("code:");
    sb.append(this.code);
    first = false;
    if (!first) {
      sb.append(", ");
    }
    sb.append("ids:");
    if (this.ids == null) {
      sb.append("null");
    } else {
      sb.append(this.ids);
    }
    first = false;
    if (isSetMsg()) {
      if (!first) {
        sb.append(", ");
      }
      sb.append("msg:");
      if (this.msg == null) {
        sb.append("null");
      } else {
        sb.append(this.msg);
      }
      first = false;
    }
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(
          new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException,
      ClassNotFoundException {
    try {
      // it doesn't seem like you should have to do this, but java serialization is wacky, and
      // doesn't call the default constructor.
      issetBitfield = 0;
      read(new org.apache.thrift.protocol.TCompactProtocol(
          new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class IdsResultStandardSchemeFactory implements SchemeFactory {
    public IdsResultStandardScheme getScheme() {
      return new IdsResultStandardScheme();
    }
  }

  private static class IdsResultStandardScheme extends StandardScheme<IdsResult> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, IdsResult struct)
        throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true) {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
          break;
        }
        switch (schemeField.id) {
          case 1: // CODE
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.code = iprot.readI32();
              struct.setCodeIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // IDS
            if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
              {
                org.apache.thrift.protocol.TList list = iprot.readListBegin();
                struct.ids = new ArrayList<Long>(list.size);
                long elem1;
                for (int i = 0; i < list.size; ++i) {
                  elem1 = iprot.readI64();
                  struct.ids.add(elem1);
                }
                iprot.readListEnd();
              }
              struct.setIdsIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // MSG
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.msg = iprot.readString();
              struct.setMsgIsSet(true);
            } else {
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, IdsResult struct)
        throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      oprot.writeFieldBegin(CODE_FIELD_DESC);
      oprot.writeI32(struct.code);
      oprot.writeFieldEnd();
      if (struct.ids != null) {
        oprot.writeFieldBegin(IDS_FIELD_DESC);
        {
          oprot.writeListBegin(new org.apache.thrift.protocol.TList(
              org.apache.thrift.protocol.TType.I64, struct.ids.size()));
          for (long iter : struct.ids) {
            oprot.writeI64(iter);
          }
          oprot.writeListEnd();
        }
        oprot.writeFieldEnd();
      }
      if (struct.msg != null) {
        if (struct.isSetMsg()) {
          oprot.writeFieldBegin(MSG_FIELD_DESC);
          oprot.writeString(struct.msg);
          oprot.writeFieldEnd();
        }
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class IdsResultTupleSchemeFactory implements SchemeFactory {
    public IdsResultTupleScheme getScheme() {
      return new IdsResultTupleScheme();
    }
  }

  private static class IdsResultTupleScheme extends TupleScheme<IdsResult> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, IdsResult struct)
        throws org.apache.thrift.TException {
      BitSet optionals = new BitSet();
      if (struct.isSetCode()) {
        optionals.set(0);
      }
      if (struct.isSetIds()) {
        optionals.set(1);
      }
      if (struct.isSetMsg()) {
        optionals.set(2);
      }
      TTupleProtocol oprot = (TTupleProtocol) prot;
      oprot.writeBitSet(optionals, 3);
      if (struct.isSetCode()) {
        oprot.writeI32(struct.code);
      }
      if (struct.isSetIds()) {
        {
          oprot.writeI32(struct.ids.size());
          for (long iter : struct.ids) {
            oprot.writeI64(iter);
          }
        }
      }
      if (struct.isSetMsg()) {
        oprot.writeString(struct.msg);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, IdsResult struct)
        throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(3);
      if (incoming.get(0)) {
        struct.code = iprot.readI32();
        struct.setCodeIsSet(true);
      }
      if (incoming.get(1)) {
        {
          org.apache.thrift.protocol.TList list =
              new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.I64,
                  iprot.readI32());
          struct.ids = new ArrayList<Long>(list.size);
          long elem;
          for (int i = 0; i < list.size; ++i) {
            elem = iprot.readI64();
            struct.ids.add(elem);
          }
        }
        struct.setIdsIsSet(true);
      }
      if (incoming.get(2)) {
        struct.msg = iprot.readString();
        struct.setMsgIsSet(true);
      }
    }
  }

}
